package com.szu.subject.domains;

import java.sql.Time;
import java.util.ArrayList;
import java.util.List;

import javax.lang.model.type.PrimitiveType;

import org.apache.commons.lang.StringUtils;

public class TimeObject {

	private String type;
	private String day;
	private List<String> number;
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	public String getDay() {
		return day;
	}
	public void setDay(String day) {
		this.day = day;
	}
	public List<String> getNumber() {
		return number;
	}
	public void setNumber(List<String> number) {
		this.number = number;
	}
	
	public void addNumber(String c) {
		this.number.add(c);
	}
	
	public void addNumber(List<String> c) {
		this.number.addAll(c);
	}
	
	public static List<TimeObject> geTimeObject(String timeString){
		if(StringUtils.isEmpty(timeString)){
			return null;
		}
		String[] times=timeString.split(";");
		String[] detail;
		List<TimeObject> timeObjects=new ArrayList<>(times.length);
		int length;
		TimeObject timeObject;
		for(String time:times){
			timeObject=new TimeObject();
			detail=time.split("_");
			timeObject.setType(detail[0]);
			timeObject.setDay(detail[1]);
			length=detail[2].length();
			timeObject.setNumber(new ArrayList<>(length));
			for(int i=0;i<length;i++){
				Character c=detail[2].charAt(i);
				timeObject.addNumber(c.toString());
			}
			timeObjects.add(timeObject);
		}
		return timeObjects;
	}
	
	@Override
	public String toString(){
		return day+"-"+number.toString()+"-"+type;
	}
	
	@Override
	 public int hashCode(){
		return toString().hashCode();
	}
	
	@Override
	public boolean equals(Object object){
		if(object instanceof TimeObject){
			int length;
			List<String> temp;
			TimeObject timeObject=(TimeObject) object;
			if(this.day.equals(timeObject.getDay())){
				length=timeObject.getNumber().size();
				for(int i=0;i<length;i++)
					if(this.number.contains(timeObject.getNumber().get(i))){
						if(this.type.equals(timeObject.getType())||"00".equals(this.type)||"00".equals(timeObject.getType())){
							return true;
						}
					}
			}
		}
		return false;
		
	}
	
}
